package com.iknow.view.widget;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import com.iknow.IKnow;
import com.iknow.util.MsgDialog;
import com.iknow.util.MsgDialog.ProgressHandler;
import com.iknow.util.MsgDialog.ProgressRunnable;
import com.iknow.util.StringUtil;
import java.io.File;

public class SystemUpdate
{
  private static boolean isMust;
  private static String url;
  private UpdateCallBack callBack;
  public Context ctx;
  private File file = null;

  private SystemUpdate()
  {
    this.callBack = null;
  }

  private void downApk()
  {
    MsgDialog.showProgressDialog(this.ctx, new MsgDialog.ProgressRunnable(this)
    {
      public boolean runnable()
      {
        paramHandler.obtainMessage().sendToTarget();
        return true;
      }
    }
    , new MsgDialog.ProgressHandler(this)
    {
      public void handleMessage(, ProgressDialog paramProgressDialog)
      {
        if ((SystemUpdate.access$3(this.this$0) == null) || (!(SystemUpdate.access$3(this.this$0).exists())))
          MsgDialog.showB2Dilog(this.this$0.ctx, 2131361829, new DialogInterface.OnClickListener(this)
          {
            public void onClick(, int paramInt)
            {
              switch (paramInt)
              {
              default:
              case -1:
              case -2:
              }
              while (true)
              {
                while (true)
                {
                  return;
                  SystemUpdate.access$0(SystemUpdate.3.access$0(this.this$1));
                }
                MsgDialog.showB2Dilog(SystemUpdate.3.access$0(this.this$1).ctx, 2131361842, new DialogInterface.OnClickListener(this)
                {
                  public void onClick(, int paramInt)
                  {
                    switch (paramInt)
                    {
                    default:
                    case -1:
                    case -2:
                    }
                    while (true)
                    {
                      while (true)
                      {
                        while (true)
                        {
                          return;
                          SystemUpdate.access$0(SystemUpdate.3.access$0(SystemUpdate.3.1.access$0(this.this$2)));
                        }
                        if (!(SystemUpdate.access$1()))
                          break;
                        IKnow.exitSystem();
                      }
                      SystemUpdate.access$2(SystemUpdate.3.access$0(SystemUpdate.3.1.access$0(this.this$2))).callBack();
                    }
                  }
                });
              }
            }
          });
        while (true)
        {
          return;
          SystemUpdate.access$4(this.this$0);
        }
      }
    });
  }

  public static SystemUpdate getUpdate()
  {
    return new SystemUpdate();
  }

  private void install()
  {
    if ((this.file == null) || (!(this.file.exists())));
    while (true)
    {
      return;
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.setDataAndType(Uri.parse("file://" + this.file.getPath()), "application/vnd.android.package-archive");
      this.ctx.startActivity(localIntent);
    }
  }

  public static void setUpdate(String paramString, boolean paramBoolean)
  {
    url = paramString;
    isMust = paramBoolean;
  }

  public void update(Context paramContext, UpdateCallBack paramUpdateCallBack)
  {
    int i;
    if (paramUpdateCallBack == null);
    while (true)
    {
      return;
      if ((!(StringUtil.isEmpty(url))) && (paramContext != null))
        break;
      paramUpdateCallBack.callBack();
    }
    this.callBack = paramUpdateCallBack;
    this.ctx = paramContext;
    if (isMust)
      i = 2131361830;
    while (true)
    {
      while (true)
        MsgDialog.showB2Dilog(paramContext, i, new DialogInterface.OnClickListener(this)
        {
          public void onClick(, int paramInt)
          {
            switch (paramInt)
            {
            default:
            case -1:
            case -2:
            }
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  return;
                  SystemUpdate.access$0(this.this$0);
                }
                if (!(SystemUpdate.access$1()))
                  break;
                Process.killProcess(Process.myPid());
              }
              SystemUpdate.access$2(this.this$0).callBack();
            }
          }
        });
      i = 2131361829;
    }
  }

  public static abstract interface UpdateCallBack
  {
    public abstract void callBack();
  }
}